package maksb.logger;


public class MyLogger {
    private String name;
    
    private LoggerLevel level;

    private FileAppender appender;
    
    public MyLogger(String name) {
        this.name = name;
        init();
    }

    private void log(String str) {
        appender.append(str);
    }
    
    public void init() {
        String logFile = System.getProperty("mylogger.file.name", "superlog.log");
        appender = new FileAppender(logFile);
        String levelStr = System.getProperty("mylogger." + name + ".level", "INFO");
        level = LoggerLevel.valueOf(levelStr);
    }
    
    public void log(LoggerLevel level, String msg) {
        log(MessageFormatter.format(name, level, msg));
    }
    
    public void log(LoggerLevel level, String msg, Throwable e) {
        throw new UnsupportedOperationException();
    }

    public void log(LoggerLevel level, String format, Object... arg) {
        throw new UnsupportedOperationException();
    }
    public boolean isErrorEnabled() {
        return isWarnEnabled() || LoggerLevel.ERROR.equals(level);
    }
    public boolean isWarnEnabled() {
        return isInfoEnabled() || LoggerLevel.WARN.equals(level);
    }
    public boolean isInfoEnabled() {
        return isDebugEnabled() || LoggerLevel.INFO.equals(level);
    }
    public boolean isDebugEnabled() {
        return isTraceEnabled() || LoggerLevel.DEBUG.equals(level);
    }
    public boolean isTraceEnabled() {
        return LoggerLevel.TRACE.equals(level);
    }

    
}
